from typing import Literal

from fastapi.responses import JSONResponse
from pydantic import confloat

from common.base.base_routers import get_custom_router
from services.ocb.api import OcbApi
from common.utils import make_literal
from settings import settings

ocb_api = OcbApi()
ocb_router = get_custom_router(ocb_api, prefix='/ocb', tags=['ocb'])


@ocb_router.get('/set-ocb-threshold/', response_class=JSONResponse)
async def set_ocb_thresholds(name: make_literal(settings.OCB_METHODS_KEYS), value: confloat(ge=0, le=7)):
    return await ocb_api.set_ocb_threshold(name, value)


@ocb_router.get('/get-all-ocb-thresholds/', response_class=JSONResponse)
async def get_all_ocb_thresholds():
    return await ocb_api.get_all_ocb_thresholds()


@ocb_router.get('/get-ocb-threshold/', response_class=JSONResponse)
async def get_ocb_threshold(name: Literal[tuple(settings.OCB_METHODS_KEYS)]):
    return await ocb_api.get_ocb_threshold(name)


@ocb_router.get('/get-all-ocb-current-28v/', response_class=JSONResponse)
async def get_all_ocb_current28v():
    return await ocb_api.get_all_ocb_current_28v()


@ocb_router.get('/get-ocb-current-28v/', response_class=JSONResponse)
async def get_all_ocb_current28v(name: str):
    all_ocb_thresholds = await ocb_api.get_all_ocb_current_28v()
    return all_ocb_thresholds.get(name)


@ocb_router.get('/get-all-ocb-states/', response_class=JSONResponse)
async def get_all_ocb_states():
    return await ocb_api.get_all_ocb_states()

@ocb_router.get('/read-services-ocb/', response_class=JSONResponse)
async def read_services_ocb():
    return await ocb_api.read_services_ocb()







